const fs = require('fs');
const path = require('path')

class HtmlPlugin {
    constructor() { }
    apply(compiler) {
        // 监听 done 构造完成钩子
        compiler.hooks.done.tap('done', () => {
            const read = fs.createReadStream(path.join(process.cwd(), 'public', 'index.html'));
            const write = fs.createWriteStream(path.join(process.cwd(), 'dist', 'index.html'));
            read.pipe(write); // 拷贝文件
        });
    }
}

module.exports = HtmlPlugin;